package com.example.demo_activity

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

/**
 onCreate--》onStart----》onResume--》onPause----》onStop----》onDestroy      onRestart
 onPause:失去焦点，界面可见，但是不能响应
 onStop:停止，界面不可见
1.Activity A跳转Activity B，再按返回键，生命周期执行的顺序？
 显示A：onCreate(A)-->onStart(A)-->onResume(A)
 A跳转B：onPause(A)-->onCreate(B)-->onStart(B)-->onResume(B)-->onStop(A)
 按返回键:onPause(B)-->onRestart(A)-->onStart(A)-->onResume(A)--->onStop(B)-->onDestroy(B)
 按返回键：onPause（A）-->onStop(A)-->onDestroy(A)





 */
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        Log.d("TAG", "onCreate: ")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        outState.putString("name","yaotianxue")
        Log.d("TAG", "onSaveInstanceState保存数据:")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        val name = savedInstanceState.getString("name")
        Log.d("TAG", "onRestoreInstanceState恢复数据: $name")
    }
    override fun onDestroy() {
        super.onDestroy()
        Log.d("TAG", "onDestroy: ")
    }

    fun xiaohui(view: View) {
        finish()
    }

}